package model.code.line;

import model.symbol.Directive;
import model.symbol.Constant;
import model.symbol.DataType;
import model.symbol.LocalVariable;
import model.code.GlobalVariable;

/**
 * A Token represents a piece of a {@link Line}, including white-space, usually with an
 * associated object, such as a Symbol whose name is contained in the text of the Token.
 *
 * @author Neil Dickson
 */
public class Token {
	private String	text;
	private	Object	object;

	public Token(String text, Object object) {
		this.text = text;
		this.object = object;
	}

	public String getText() {
		return text;
	}

	public Object getObject() {
		return object;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void setObject(Object object) {
		this.object = object;
	}

	public String toString() {
		return text;
	}
	public int length() {
		return text.length();
	}

	public boolean isWhiteSpace() {
		return object==Line.WHITE_SPACE_MARKER;
	}
	public boolean isOperator() {
		return object==Line.OPERATOR_MARKER;
	}
	public boolean isOperator(String op) {
		return object==Line.OPERATOR_MARKER && text.equals(op);
	}
	public boolean isUnknown() {
		return object==null;
	}
	public boolean isStringLiteral() {
		return object==Line.STRING_LITERAL_MARKER;
	}

	public boolean isImmediateStart() {
		return (isOperator() && !isOperator("[")) || isStringLiteral() || object instanceof Number || object instanceof Directive || object instanceof Constant;
	}

	public boolean isMemoryStart() {
		return isOperator("[") || object instanceof DataType || object instanceof GlobalVariable || object instanceof LocalVariable;
	}
}
